public class test5 {
    //力扣 153. 寻找旋转排序数组中的最小值
    public static void main(String[] args) {
        int[] arr = {2,3,1};
        System.out.println(findMin(arr));

        System.out.println(findMin2(arr));
    }

    public static int findMin(int[] nums) {
        int left = 0, right = nums.length - 1, mid = 0;
        int x = nums[right];
        while (left < right) {
            mid = left + (right - left) / 2;
            if (nums[mid] > x) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        return nums[left];
    }

    //有待修改
    public static int findMin2(int[] nums) {
        int left = 0, right = nums.length - 1, mid = 0;
        int x = nums[0];
        while (left < right) {
            mid = left + (right - left) / 2;
            if (nums[mid] < x) {
                right = mid;
            } else {
                left = mid+1 ;
            }
        }
        return  left==nums.length-1?nums[0]: nums[left];
    }

}
